package cn.usts.edu.lesson03;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestWindowsListener {
    public static void main(String[] args) {
        new WindowsListenerFrame();
    }
}


class WindowsListenerFrame extends Frame{
    public WindowsListenerFrame() {
        setBounds(200,200,400,200);
        setVisible(true);
        // 匿名内部类
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                setVisible(false);// 隐藏窗口
            }
        });

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowActivated(WindowEvent e) {
                WindowsListenerFrame windowsListenerFrame = (WindowsListenerFrame) e.getSource();
                windowsListenerFrame.setTitle("被激活了");
            }
        });

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowDeactivated(WindowEvent e) {
                WindowsListenerFrame source = (WindowsListenerFrame) e.getSource();
                source.setTitle("没有被激活");
            }
        });
    }

}